<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<title>个人资料管理-资料修改</title>
<%@ include file="../../../common/base.jsp" %>
</head>

<body id="body">
<!--head-->
<div id="head">
	<%@ include file="../../../common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
	<div id="pageId" style="display: none;">04-03-02</div>
		<!--sidebar-->
		<%@ include file="../../../common/menu.jsp" %>
	    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location">
        	系统管理<span>&gt;</span>个人资料管理<span>&gt;</span>
        </div>
        <!--content-->
        <div class="content">
            <h2 class="tit_blue">个人基本信息：</h2>
            <div class="inputInfoList3">
                <ul>
                    <li>
                        <label>登录名：</label><span>${ossOperatorVO.loginName }</span>
                    </li>
                    <li>
                        <label>注册时间：</label><span>${ossOperatorVO.createTimeDesc}</span>
                    </li>
                    <li>
                        <label>姓名：</label><input type="text" onFocus="this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'" class="text" id="name" name="name" value="${ossOperatorVO.name }">
                    </li>
                    <li>
                        <label>所属部门：</label>
                        <select id="department" name="department">
                            <c:forEach items="${departmentType}" var="dt" varStatus="s"> 
                            	<c:if test="${ossOperatorVO.department == dt.enumCode}">
                            		<option value="${dt.enumCode }" selected="selected">${dt.enumName }</option>
                            	</c:if>
                            	<c:if test="${ossOperatorVO.department != dt.enumCode}">
                            		<option value="${dt.enumCode }">${dt.enumName }</option>
                            	</c:if>
                            </c:forEach>
                        </select>
                    </li>
                    <li>
                        <label>职称：</label>
                        <select id="position" name="position">
                            <c:forEach items="${positionType}" var="pt" varStatus="s"> 
                            	<c:if test="${ossOperatorVO.position == pt.enumCode}">
                            		<option value="${pt.enumCode }" selected="selected">${pt.enumName }</option>
                            	</c:if>
                            	<c:if test="${ossOperatorVO.position != pt.enumCode}">
                            		<option value="${pt.enumCode }">${pt.enumName }</option>
                            	</c:if>
                            </c:forEach>
                        </select>
                    </li>
                </ul>
                <div class="button_wrap button_wrap2">
                	<a href="javascript:;" class="bg_blue" onClick="updateOperator();">修改</a>
                </div>
            </div>
            <h2 class="tit_blue mg_tb_10">当前权限：</h2>
            <div id="roleListDiv">
            <!--角色列表-->
            <div class="listBox">
                <ul id="roleList">
                
                </ul>
            </div>
            <!--角色列表-->
            <!--权限列表-->
            <div class="listBox">
                <ul id="rightTree">
                	
                </ul>
            </div>
            <!--权限列表-->
            </div>
        </div>
        <!--content-->
        <!--foot-->
        <div id="foot">
        	<p>北京掌中彩信息科技有限公司  提供技术支持</p>
        </div>
        <!--foot-->
    </div>
    <!--main-->
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">

var TOP_MENUID = "100000000";

$(document).ready(function(e) {
	$("#rightTree li").attr("id",TOP_MENUID);
	init();
});
//初始化加载角色列表、权限树相关数据
function init(){
	$.ajax({
		   type: "POST",
		   url: "${pageContext.request.contextPath}/user/queryTreeByOperatorId",
		   dataType:"json",
		   data:{
			   operatorId:"${operatorId}"
		   },
		   beforeSend:function(XMLHttpRequest){
				$("#roleListDiv").showLoading();
				flagTable = true;
	       },
	       error:function(XMLHttpRequest, textStatus, errorThrown){
	        	prompt.alert("系统错误");
	        	$("#roleListDiv").hideLoading();
	        },
		   success: function(data){		   		
		   		var partnerData = data.partnerData;
		   		var chData = data.chData;
		   		var rightData = data.rightData;
		   		//绑定渠道列表数据
		   		//console.log(JSON.stringify(partnerData));
		   		if(partnerData != null && partnerData.length > 0){
			   		for (var i = 0; i < partnerData.length; i++) {
			   			var partnerId = partnerData[i].PARTNER_ID;
						$("#roleList").append("<li><input name='rolePartner' type='checkbox' class='cb' onclick='reCb(this);' disabled='disabled' value='"+partnerData[i].PARTNER_ID	
							+"' "+partnerData[i].CHECKED+"><span>"+partnerData[i].NAME+"</span></li>");
						for (var j = 0; j < chData.length; j++) {	
							if(partnerId == chData[j].PARENT_PARTNERID){
								$("#roleList").append("<li style='margin-left: 20px;'><input name='rolePartner' type='checkbox' disabled='disabled' class='cb' onclick='reCb(this);' value='"+chData[j].PARTNER_ID	
									+"' "+chData[j].CHECKED+"><span>"+chData[j].NAME+"</span></li>");
							}
						}
					}
		   		}else{
		   			for (var i = 0; i < chData.length; i++) {
						$("#roleList").append("<li><input name='rolePartner' type='checkbox' class='cb' onclick='reCb(this);' disabled='disabled' value='"+chData[i].PARTNER_ID	
							+"' "+chData[i].CHECKED+"><span>"+chData[i].NAME+"</span></li>");
					}
		   		}
				//绑定权限树数据
		   		//console.log(JSON.stringify(rightData));
				for (var j = 0; j < rightData.length; j++) {
					createMenuTree(rightData[j]);
				}
				$("#roleListDiv").hideLoading();
				/*if ("${type}"=="update") {
					initRoleCb();
					initRightCb();
				}*/
		   }
	});
}

//创建权限树
function createMenuTree(obj){
	var li = "<li id="+obj.MENU_ID+" value="+obj.PARENT_MENU_ID+"><input type='checkbox' disabled='disabled' value='"+
		obj.MENU_ID+"'" +obj.CHECKED+" onclick='selectCb("+obj.MENU_ID+","+obj.PARENT_MENU_ID+
			");'><span onclick='spread("+obj.MENU_ID+");'>"+obj.MENU_NAME+"</span></li>";
	if (obj.PARENT_MENU_ID==TOP_MENUID) {//一级菜单
		$("#rightTree").append(li);
		$("#"+obj.MENU_ID+" input").attr("class",obj.PARENT_MENU_ID);
	}else {
		$("#"+obj.PARENT_MENU_ID).append("<ul class="+obj.PARENT_MENU_ID+" style='display:none;'>"+li+"</ul>");//找父节点追加元素
	}
	if (obj.SUB_DATA!=undefined) {
		$("#"+obj.MENU_ID+" span").before("<i class='triangle_l'/>");
		for (var i = 0; i < obj.SUB_DATA.length; i++){
			createMenuTree(obj.SUB_DATA[i]);
		}
	}
}

//权限树单个展开收缩
function spread(clsName){
	$("."+clsName).each(function(i,e){
		if ($(e).is(":hidden")) {
			$(e).show();
		} else {
			$(e).hide();
		}
	});
}

//权限树单个checkbox处理方法
function selectCb(menuId,parentMenuId){
	var flag = false;
	//子节点处理
	$("."+menuId+" input").each(function(i,e){//查询子元素下所有checkbox
		if ($("#"+menuId+" input:eq(0)").attr("checked")) {//当前checkbox
			$(e).attr("checked",true);
		} else {
			$(e).attr("checked",false);
		}
	});
	
	if ($("#"+menuId+" input:eq(0)").attr("checked")) {
		flag = true;
	}
	dealParent(parentMenuId,flag);
}

function updateOperator(){
	var department = $("#department").val();
	var position = $("#position").val();
	var name = $("#name").val();
	//开始提交更新渠道信息
    $.ajax({ 				//请求登录处理页
    	contentType:"aplication/x-www-form-urlencoded; charset=UTF-8",
        url: "user/updateUserModify",  
        //传送请求数据
        data: { department: department, 
        	position: position,
        	name:encodeURIComponent(name)
        },
        success: function(data, status){
            prompt.alert(data.msg);                	
	    },error: function (data, status, e){
	    	prompt.alert(data.msg);
	    }
    });
}
</script>
</body>
</html>